package miage.rest.xml.xstream.converter;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.ConverterLookup;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

/**
 * Classe abstraite d'un décorateur de converter
 * 
 * @author Schwartz Michaël
 */
public abstract class AbstractConverterDecorator implements ConverterDecorator {

	private Converter decoratedConverter;

	/**
	 * @require decoratedConverter != null
	 * 
	 * @param decoratedConverter
	 */
	public AbstractConverterDecorator(Converter decoratedConverter) {
		this.decoratedConverter = decoratedConverter;
	}

	/**
	 * @require decoratedConverter != null
	 * @require converterLookup != null
	 * 
	 * @param target
	 * @param converterLookup
	 */
	public AbstractConverterDecorator(Class target, ConverterLookup converterLookup) {
		this(converterLookup.lookupConverterForType(target));
	}

	

	public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
		this.getDecoratedConverter().marshal(source, writer, context);
	}

	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		return this.getDecoratedConverter().unmarshal(reader, context);
	}

	

	public Converter getDecoratedConverter() {
		return decoratedConverter;
	}

	
}
